﻿// ******************************************************************
// * Copyright(c)  Steven Lu
// * Description   : Entity_SEC_USER_ROLE
// * CreateDate    : 2011/7/13 18:40:36
// * Creater       : CodeSmith
// * LastChangeDate: 2011/7/13 18:40:36
// * LastChanger   : 2011/7/13 18:40:36
// * Version Info  : 1.0 For ESOL
// ******************************************************************

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Suzsoft.Smart.Data;
using ESOL.Common.Entity;

namespace ESOL.Business.Sec
{
    /// <summary>
    /// SecUserRole
    /// </summary>
    public partial class SecUserRoleBs
    {
        #region GetByID
        /// <summary>
        /// Get Entity
        /// </summary>
        /// <param name="objSecUserRoleEntity">Entity</param>
        /// <returns>Entity</returns>
        public static SecUserRoleEntity GetSecUserRole(SecUserRoleEntity objSecUserRoleEntity)
        {
            return DataAccess.SelectSingle<SecUserRoleEntity>(objSecUserRoleEntity);
        }
        public static List<SecUserRoleEntity> GetSecUserRolesByUserID(string userID)
        {
            if (string.IsNullOrEmpty(userID))
            {
                return null;
            }
            SecUserRoleEntity entity = new SecUserRoleEntity();
            entity.UserId = userID;
            return DataAccess.Select<SecUserRoleEntity>(entity);
        }
        public static List<SecUserRoleEntity> GetSecUserRolesByRoleID(string roleID)
        {
            if (string.IsNullOrEmpty(roleID))
            {
                return null;
            }
            SecUserRoleEntity entity = new SecUserRoleEntity();
            entity.RoleId = roleID;
            return DataAccess.Select<SecUserRoleEntity>(entity);
        }
        #endregion


        #region Insert
        /// <summary>
        /// Insert Data
        /// </summary>
        /// <param name="objSecUserRoleEntity">Entity</param>
        /// <returns>true Insert Succeed; false Insert Fail</returns>
        public static bool InsertSecUserRole(SecUserRoleEntity objSecUserRoleEntity)
        {
            return DataAccess.Insert(objSecUserRoleEntity);
        }

        public static bool InsertSecUserRole(List<SecUserRoleEntity> objSecUserRoleEntityList)
        {
            return DataAccess.Insert(objSecUserRoleEntityList);
        }
        #endregion


        #region Update
        /// <summary>
        /// Update Data
        /// </summary>
        /// <param name="objSecUserRoleEntity">Entity</param>
        /// <returns>true Update Succeed; false Update Fail</returns>
        public static bool UpdateSecUserRole(SecUserRoleEntity objSecUserRoleEntity)
        {
            return DataAccess.Update(objSecUserRoleEntity);
        }

        public static bool UpdateSecUserRole(List<SecUserRoleEntity> objSecUserRoleEntityList)
        {
            return DataAccess.Update<SecUserRoleEntity>(objSecUserRoleEntityList);
        }
        #endregion


        #region Delete
        /// <summary>
        /// Delete Data
        /// </summary>
        /// <param name="objSecUserRoleEntity">Entity</param>
        /// <returns>true Delete Succeed; false Delete Fail</returns>
        public static bool DeleteSecUserRole(SecUserRoleEntity objSecUserRoleEntity)
        {
            return DataAccess.Delete(objSecUserRoleEntity);
        }

        public static bool DeleteSecUserRole(List<SecUserRoleEntity> objSecUserRoleEntityList)
        {
            return DataAccess.Delete<SecUserRoleEntity>(objSecUserRoleEntityList);
        }
        #endregion


        #region GetAll
        /// <summary>
        /// Get All Data
        /// </summary>
        /// <returns>Back All Data<returns>
        public static DataSet GetSecUserRoleAll()
        {
            return DataAccess.SelectAllDataSet<SecUserRoleEntity>();
        }
        #endregion


        #region Functions
        public static bool SaveUserRole(List<SecUserRoleEntity> list, string userID)
        {
            using (DataAccessBroker broker = DataAccessFactory.Instance())
            {
                try
                {
                    broker.BeginTransaction();
                    //Delete
                    string sql = "DELETE FROM SEC_USER_ROLE WHERE USER_ID = '" + userID + "'";
                    broker.ExecuteSQL(sql);
                    //Add
                    DataAccess.Insert<SecUserRoleEntity>(list, broker);
                    broker.Commit();
                }
                catch (Exception ex)
                {
                    broker.RollBack();
                    throw ex;
                }
            }
            return true;
        }
        #endregion
    }


}

